package com.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action=req.getParameter("action");
        if("login".equals(action)){
            String username = req.getParameter("username");
            String password = req.getParameter("password");
            if("dhxamxy".equals(username)&&"151629".equals(password)){
                req.getSession().setAttribute("jiaoyan",username);
            }else {
                resp.sendRedirect(req.getContextPath() + "you are a SB!");
                resp.sendRedirect(req.getHeader("Referer"));
            }
        }
    }
}
